package com.linkage.bookshop.authentication;



import javax.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.linkage.bookshop.repository.UserRepository;



@Component
public class MyUserCredentialProvider implements UserDetailsService{
	@Resource
	private UserRepository userRepository;

	@Transactional
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {		
		UserCredential userCredential = new UserCredential(userRepository.selectUserSecurity(username));
		if(userCredential.getUser() == null){
			throw new UsernameNotFoundException("");
		}
		return userCredential;
	}

}
